home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / uemlsrc.arc / kertty.c < prev    next >
C/C++ Source or Header  |  1987-08-24  |  8KB  |  230 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <osbind.h>
  4. #include "ed.h"
  5. #include "kermit.h"
  6.  
  7. #ifndef ESC
  8. #define ESC 0x1b
  9. #endif
  10. #ifndef DEL
  11. #define DEL 0x7f
  12. #endif
  13.  
  14. extern  int *aline_addr; /* Ptr to base of Aline variables */
  15. extern  int sav_row, sav_col;
  16.  
  17. typedef struct MACTAB {
  18.         struct  MACTAB  *m_fmac;        /* next MACTAB  */
  19.         short   *keymac;                /* pointer to the macro */
  20.         char    key;                    /* the key      */
  21. } MACTAB;
  22.  
  23. /* Do a direct read of the console. The present scheme does not always
  24.  * work with a minimal NULL modem (i.e. only lines 1,2,&3 connected).
  25.  */
  26. readcon()
  27. {
  28.  
  29.         register int c,i;
  30.         extern MACTAB *mheadp, *mcralloc();
  31.         register MACTAB *mt;
  32.         char fname[16];
  33.         extern char *getfname();
  34.         extern short getktpcode();
  35.  
  36.         c=getkkey();    /* Read the keyboard and get mask */
  37.         if (c == '`')   /* keyboard macro */
  38.                 {
  39.                 c = (*term.t_getchar)();
  40.                 if (c == '`')
  41.                         {
  42.                         sendaux('`');
  43.                         return(TRUE);
  44.                         }
  45.                 if (mheadp==NULL || mheadp->m_fmac == NULL)
  46.                         {
  47.                         mtwrite("No defineable macros assigned");
  48.                         return(TRUE);
  49.                         }
  50.                 if((mt=mcralloc(FALSE,c))!= (MACTAB *)NULL)
  51.                         sendmacro(mt->keymac);
  52.                 }
  53.         else if (shiftstatus == 12 && scancode == 0x30) /* CTRL-ALT-B */
  54.                 sendbrk();
  55.         else if (shiftstatus == 12 && scancode == 0x2e) /* CTRL-ALT-C */
  56.                 {
  57.                 setterm(HOST);
  58.                 shell(FALSE,HUGE);
  59.                 setterm(REMOTE);
  60.                 }
  61.         else if (shiftstatus == 17 || shiftstatus == 18) /* C-Lock + Shift */
  62.                 {
  63.                 i=tolower(c);
  64.                 sendaux(i);
  65.                 }
  66.         else if (shiftstatus == 0 && scancode == 0x62) /* HELP Key */
  67.                 setterm(SHOWHELP);
  68.         else if (shiftstatus == 8)      /* ALT key pressed */
  69.                 {
  70.                 switch(scancode)
  71.                         {
  72.                         case 0x12:      /* E */
  73.                         /* save cursor position */
  74.                                 sav_row = aline_addr[-13];
  75.                                 sav_col = aline_addr[-14];
  76.                                 commfil(TRUE,TRUE);
  77.                                 ttopen();       /* update color */
  78.                                 (*term.t_move)(sav_row,sav_col);
  79.                                 return(TRUE);
  80.                         case 0x61:      /* UNDO */
  81.                                 return(FALSE);
  82.                         case 0x2e:      /* C */
  83.                         /* save cursor position */
  84.                                 sav_row = aline_addr[-13];
  85.                                 sav_col = aline_addr[-14];
  86.                                 paintbuffer(TRUE,TRUE);
  87.                                 (*term.t_move)(sav_row,sav_col);
  88.                                 return(TRUE);
  89.                         case 0x30:      /* B */
  90.                                 return(setbaud());
  91.                         case 0x26:      /* L */
  92.                                 sav_row = aline_addr[-13];
  93.                                 sav_col = aline_addr[-14];
  94.                                 loadmac(TRUE);
  95.                                 (*term.t_move)(sav_row,sav_col);
  96.                                 return(TRUE);
  97.                         case 0x18:      /* O */
  98.                                 /* Turn off flow control */
  99.                                 flow = NOFLO;
  100.                                 Rsconf(-1,flow,-1,-1,-1,-1);
  101.                                 mtwrite("[Handshaking disabled]");
  102.                                 return(TRUE);
  103.                         case 0x13:      /* R */
  104.                                 flow = RTS;
  105.                                 Rsconf(-1,flow,-1,-1,-1,-1);
  106.                                 mtwrite("[RTS/CTS active]");
  107.                                 return(TRUE);
  108.                         case 0x14:
  109.                                 showtime(TRUE,HUGE);
  110.                                 return(TRUE);
  111.                         case 0x2d:      /* X */
  112.                                 flow = XON;
  113.                                 Rsconf(-1,flow,-1,-1,-1,-1);
  114.                                 mtwrite("[XON/XOFF active]");
  115.                                 return(TRUE);
  116.                         case 0x35:      /* / ? */
  117.                                 setterm(SHOWHELP);
  118.                                 return(TRUE);
  119.                         default:
  120.                                 sendaux(c);
  121.                                 return(TRUE);
  122.                         }
  123.                 }
  124.         else
  125.                 {
  126.                 if (c & SPEC)
  127.                         if (getfname(c,fname)!=(char *)NULL)
  128.                                 c = (int)getktpcode(fname);
  129.                 if (c & META)
  130.                         {
  131.                         i = c & ~META;
  132.                         sendaux(ESC);
  133.                         c = i;
  134.                         }
  135.                 if (c & CTLX)
  136.                         {
  137.                         i = c & ~CTLX;
  138.                         sendaux(0x18);
  139.                         c = i;
  140.                         }
  141.                 if (c & CTRL)
  142.                         {
  143.                         i = c & ~CTRL;
  144.                         c = i - '@';
  145.                         }
  146.                 sendaux(c);
  147.                 }
  148.         return(TRUE);
  149. }
  150.  
  151. /* pratically identical to getkey in main.c but that one uses mlwrite
  152.  * which would damage the terminal screen when it tried to update.
  153.  */
  154. getkkey()
  155. {
  156.         register int c;
  157.         extern char keyscan[];
  158.  
  159.         c = (*term.t_getchar)();
  160. #if     ST
  161.         if (scancode == 0x70 && shiftstatus != 16)
  162.                 return (CTRL|'X');
  163. #endif
  164.         if (c == DEL)
  165.                 return(c);
  166.         if (c == METACH) {                      /* Apply M- prefix      */
  167.                 mtwrite("Meta: ");
  168.                 c = (*term.t_getchar)();
  169.                 return (META | c);
  170.         }
  171. #if     ST
  172.         /* use special keys or number pad (code >= 0x63) ?
  173.          * 0x03 = scancode for ^@ (setmark).
  174.          */
  175.         if ((c == NULL && scancode != 0x03) || scancode >= 0x4a)
  176.                 if (scancode > 0x32)
  177.                         {
  178.                         /* if CapsLock and number pad, use real numbers */
  179.                         if (shiftstatus == 16 && (scancode > 0x62 ||
  180.                                 scancode == 0x4a || scancode == 0x4e))
  181.                                 return(c);
  182.                         else
  183.                                 return (SPEC | scancode);
  184.                         }
  185.                 else    {
  186.                         c = keyscan[scancode];
  187.                         return (META | c);
  188.                         }
  189. #endif
  190.         if (c>=0x00 && c<=0x1F)                 /* C0 control -> C-     */
  191.                 c = CTRL | (c+'@');
  192.         return (c);
  193. }
  194.  
  195. /* Allows keyboard macros to go through completely on a slow and noisy line */
  196.  
  197. sendmacro(buf)
  198. register short *buf;
  199. {
  200.         register int c;
  201.         char fname[16];
  202.  
  203.         while(*buf != (CTLX|')'))
  204.                 {
  205.                 while(!(int)Cauxos())   /* wait for line to clear */
  206.                         ;
  207.                 if (*buf & SPEC)
  208.                         if (getfname(*buf,fname)!=(char *)NULL)
  209.                                 *buf = (int)getktpcode(fname);
  210.                 if (*buf & META)
  211.                         {
  212.                         c = *buf & ~META;
  213.                         sendaux(ESC);
  214.                         *buf = c;
  215.                         }
  216.                 if (*buf & CTLX)
  217.                         {
  218.                         c = *buf & ~CTLX;
  219.                         sendaux(0x18);
  220.                         *buf = c;
  221.                         }
  222.                 if (*buf & CTRL)
  223.                         {
  224.                         c = *buf & ~CTRL;
  225.                         *buf = c - '@';
  226.